﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;

public partial class admin_cms_usercontrol_SlideBar : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            loadthongtin();
            loadmenutop();
        }
    }
    protected void loadthongtin()
    {
        DataTable dtprofile = new DataTable();
        if (Session["timeout"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {


            string nameuser = Session["timeout"].ToString();
            dtprofile = DataAccess.ExeSQLToDataTable("select admin_alluser.username,admin_alluser.password,admin_alluser.picture,admin_alluser.fullname as fullname, admin_alluser.idgroup, admin_groupuser.idgroup, admin_groupuser.namegroup as Namegroup from admin_alluser,admin_groupuser where admin_alluser.idgroup = admin_groupuser.idgroup and admin_alluser.username='" + nameuser + "'");
            if (dtprofile.Rows.Count > 0)
            {
                DataList1.DataSource = dtprofile;
                DataList1.DataBind();
            }
        }
        //if (dtprofile.Rows.Count>0)
        //{
        //    string Idgroup = dtprofile.Rows[0][9].ToString();
        //    DataTable dtgroup = new DataTable();
        //    dtgroup = DataAccess.ExeSQLToDataTable("select * from admin_groupuser where idgroup='"+Idgroup+"'");
        //    if (dtgroup.Rows.Count>0)
        //    {

        //    }
        //}
    }
    protected void bt_thoat(object sender, EventArgs e)
    {
        Session.Add("timeout", null);
        Response.Redirect("login.aspx");
    }
    protected string loadmenutop()
    {
        string html = "";
        DataTable dtcha = new DataTable();
        if (Session["timeout"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {


            string name = Session["timeout"].ToString();
            dtcha = DataAccess.ExeSQLToDataTable("select * from admin_module_page where idcheck=0 order by sort asc" );
            int n = dtcha.Rows.Count;
            if (n > 0)
            {
                html += "<ul id='accordion'>";
                html += " <li class='top_level'>";
                html += "<a href='http://cvauni.edu.vn'  target='_blank'> <img width='24px' height='24px' src='style/images/icons/small/grey/laptop.ico' />";
                html += "Trang chủ";

                html += "</a>";
                html += "</li>";
                for (int i = 0; i < n; i++)
                {

                    html += " <li>";
                    html += "<a href='' class='top_level'> <img width='24px' height='24px' src='style/images/icons/small/grey/" + dtcha.Rows[i][4].ToString() + "' />";
                    html += dtcha.Rows[i][1].ToString();
                    html += "</a>";
                    string id = dtcha.Rows[i][0].ToString();
                    DataTable dtcon = new DataTable();
                    //dtcon = DataAccess.ExeSQLToDataTable("select  top(2) *  from module where idcheck='" + id + "' and username='" + name + "' ");
                    DataTable d1 = new DataTable();
                    d1 = DataAccess.ExeSQLToDataTable("select * from module where idcheck='" + id + "' and username='" + name + "'");

                    int m = d1.Rows.Count;
                    if (m > 0)
                    {
                        html += "<ul class='drawer'>";
                        for (int j = 0; j < m; j++)
                        {

                            html += "<li>";
                            html += "<a href='" + d1.Rows[j][9].ToString() + "'>";
                            html += d1.Rows[j][7].ToString();
                            html += "</a>";
                            html += "</li>";

                        }
                        html += "</ul>";
                    }

                    html += "</li>";
                }
                html += "</ul>";
            }


        }
        return html;
    }
}
